(define (accumulate op initial sequence)
    (if (null? sequence)
        initial
        (op 
            (car sequence)
            (accumulate op initial (cdr sequence))
        )
    )
)
(define (count-leaves t)
    (accumulate
        (lambda (x r)
            (+ r x) 
        )
        0
        (map 
            (lambda (items) 
                (if (pair? items)
                    (count-leaves items)
                    1
                )
            )
            t
        )
    )
)

(define x (cons (list 1 2) (list 3 4) ))
(display (count-leaves (list x )))
(newline)
(display (count-leaves (list x x)))
(exit)
